<template>
	<view class="container">
		<view class="addBox flex-ac">
			<view class="inputBox flex-ac">
				<image src="../../../static/img/ss.png" mode=""></image>
				<input v-model="form.keywords" type="text" placeholder="输入司机名称/电话" />
			</view>
			<view class="btn-search" @click="search">查询</view>
		</view>
		<view class="carList">
			<view class="item" v-for="(item,index) in list" :key="index" @click.stop="selCar(index)">
				<image class="icon-car" src="../../../static/img/driver.png" mode="aspectFill"></image>
				<view class="cell flex-ac">
					<view style="font-size: 30rpx;">{{item.userName || ''}}-{{item.phone}} </view>
				</view>
				<view class="shanchuBox">
					<image v-if="item.sel" src="../../../static/img/choice_gou.png" mode="aspectFill"></image>
					<image v-else src="../../../static/img/choice_no.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="foot">
			<view class="btnBox flex-ac">
				<view class="btn-1 middle" @click="submit">确定</view>
			</view>
			<x-botSpace></x-botSpace>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index:'',
				list: [],
				form:{
					keywords: '',
					current: 1,
					size: 20
				},
				dict: []
			}
		},
		onLoad(opt) {
			if(opt) console.log('opt:', opt)
			this.index = opt.index
			// this.getCarList()
			this.getDriverList()
		},
		onReachBottom() {
			this.form.current++
			this.getDriverList()
		},
		methods: {
			submit(){
				let obj = this.list.filter(el=>el.sel)
				var pages = getCurrentPages()
				var prevPage = pages[pages.length - 2]
				if(obj.length > 0){
					this.$Net.post('/car/setDriver',{
						driverId: obj[0].id,
						id: prevPage.$vm.list[this.index].id
					}).then(res=>{
						prevPage.$vm.list[this.index].driverName = obj[0].userName
						prevPage.$vm.list[this.index].driverPhone = obj[0].phone
						console.log('prevPage:', prevPage.$vm.list[this.index])
						prevPage.$vm.$forceUpdate()
						this.$Toast.messageIcon("操作成功")
						setTimeout(()=>{
							this.$Jump.Back(1)
						},1000)
					})
				}
			},
			search(){
				this.form.current = 1
				this.getDriverList()
			},
			selCar(index){
				this.list.map(el=>{
					el.sel = false
				})
				this.list[index].sel = !this.list[index].sel
			},
			setDriver(index){
				this.$Jump.Open('../selDriver/selDriver?index=' + index)
			},
			getDriverList(){
				this.$Net.get('/driver/page', this.form).then(res=>{
					console.log('司机列表：', res)
					if(res.data.length > 0){
						res.data.map(el=>{
							el.sel = false
						})
					}
					if(this.form.current == 1){
						this.list = res.data
					}else{
						this.list = this.list.concat(res.data)
					}
				})
			},
			
			chooseCar(){
				this.$Jump.Open('../selCar/selCar')
			}
		}
	}
</script>

<style lang="scss">
	page{ background-color: #fff; }
</style>

<style lang="scss" scoped>
	// @import './style.scss';
	.carList{
		width: 100%;
		padding-top: 100rpx;
		padding-bottom: 150rpx;
		.item{
			position: relative;
			padding: 28rpx;
			padding-left: 90rpx;
			width: 100%;
			border-bottom: 1rpx solid #f7f7f7;
			font-size: 24rpx;
			.icon-car{
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				top: 30rpx;
				left: 30rpx;
			}
			.shanchuBox{
				padding: 40rpx;
				position: absolute;
				right: 10rpx;
				top: 50%;
				transform: translateY(-50%);
				image{
					width: 30rpx;
					height: 30rpx;
				}
			}
			.cell{
				margin-bottom: 8rpx;
				.setDr{
					margin-left: 20rpx;
					color: #1684FC;
					font-size: 24rpx;
					text-decoration: underline;
				}
			}
			.label{
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #f2f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}
			.label2{
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #a1f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}
		}
	}
	.addBox{
		width: 100%;
		height: 100rpx;
		padding-left: 30rpx;
		font-size: 28rpx;
		border-bottom: 1rpx solid #f7f7f7;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
		background-color: #ffffff;
		.inputBox{
			flex: 1;
			height: 70rpx;
			border-radius: 40rpx;
			background-color: #f7f7f7;
			padding: 0 20rpx;
			input{
				flex: 1;
				color: #333;
			}
		}
		.btn-search{
			height: 100rpx;
			line-height: 100rpx;
			padding: 0 30rpx;
			color: #1F82FE;
		}
		image{
			width: 40rpx;
			height: 40rpx;
			margin-right: 10rpx;
		}
	}
	.foot {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 30rpx;
	
		.btnBox {
			width: 100%;
	
			.btn-1 {
				flex: 1;
				height: 90rpx;
				background: #1684FC;
				border-radius: 10rpx;
				color: #ffffff;
				font-size: 34rpx;
			}
	
			.btn-2 {
				flex: 1;
				height: 90rpx;
				border: 1px solid #1684FC;
				border-radius: 10rpx;
				color: #1684FC;
				font-size: 34rpx;
			}
		}
	}
</style>
